package com.ruoyi.comments.service.impl;

import com.ruoyi.comments.domain.Text;
import com.ruoyi.comments.mapper.TextMapper;
import com.ruoyi.comments.service.TextService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @Classname TextServiceImpl
 * @Description
 * @Date 2025/5/24 15:27
 * @Created by zrainpus
 */
@Service
public class TextServiceImpl implements TextService {
    @Autowired
    private TextMapper textMapper;
    @Override
    public void insert(Text text) {
        textMapper.insert(text);
    }

    @Override
    public void delete(Long id) {
        textMapper.deleteById(id);
    }

    @Override
    public void update(Text text) {
        delete(text.getId());
        insert(text);
    }

    @Override
    public List<Text> selectAll() {
        return textMapper.findAll();
    }

    @Override
    public Text getById(Long id) {
        Optional<Text> text = textMapper.findById(id);
//        Content content1 = content.get();
//        return content1;
        return text.orElse(new Text());
    }
}
